package cs3343.project.family.UI;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import cs3343.project.family.Card;
import cs3343.project.family.Character;

public class ToolCardFrame extends JFrame {

	/**
	 * Create the frame.
	 */
	public ToolCardFrame(Character character, Card card, String cardType) {
		JOptionPane.showMessageDialog(null, "You get a " + card.getDescription(), cardType, 1);
		character.addCard(card);
		for (int i = 0; i < character.getNoOfCardOwned(); i++) {
			System.out.println(character.getCardsOwned().get(i).getDescription());
		}
		System.out.println("==============^"+ character.getName()+ "^==============");
	}
	
	public static boolean searchType(Card card, String cardType) {
		int toIndex = card.getDescription().indexOf("]");

		String toChinese = "";
		
		switch (cardType) {
			case "OralCard":
				toChinese = "說話";
				break;
			case "ActionCard":
				toChinese = "動作";
				break;
			case "EventCard":
				toChinese = "事件";
				break;
		}
		
		if (card.getDescription().lastIndexOf(toChinese, toIndex) != -1)
			return true;
		return false;
	}
	
	public static String[] availableCards(Character character, String cardType) {
		int AvailableCardNum = 0;
		
		//get the combobox size
		for (int i = 0; i < character.getNoOfCardOwned(); i++) {
			if (ToolCardFrame.searchType(character.getCardsOwned().get(i), cardType))
				AvailableCardNum++;
		}
		String[] option = new String[AvailableCardNum+1];
		option[0] = "None";
		
		//add item to combobox
		for (int i = 0, j = 1; i < character.getNoOfCardOwned(); i++) {
			if (ToolCardFrame.searchType(character.getCardsOwned().get(i), cardType)) {
				option[j] = character.getCardsOwned().get(i).getDescription();
				j++;
			}
		}
		
		return option;
	} 
}
